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

Function InitializeWebGPUContext

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

Source from the content-addressed store, hash-verified

1197}
1198
1199static bool InitializeWebGPUContext(WebGPUContext* context, const ContextParams& params)
1200{
1201 TRACE_CALL;
1202 context->m_BaseContext.m_Window = params.m_Window;
1203 assert(dmPlatform::GetWindowStateParam(context->m_BaseContext.m_Window, WINDOW_STATE_OPENED));
1204 context->m_OriginalWidth = params.m_Width;
1205 context->m_OriginalHeight = params.m_Height;
1206 context->m_BaseContext.m_Width = params.m_Width;
1207 context->m_BaseContext.m_Height = params.m_Height;
1208 context->m_BaseContext.m_PrintDeviceInfo = params.m_PrintDeviceInfo;
1209 context->m_BaseContext.m_VerifyGraphicsCalls = params.m_VerifyGraphicsCalls;
1210 context->m_CurrentScratchUniforms.m_Allocs.SetCapacity(32);
1211
1212 context->m_CurrentPipelineState = GetDefaultPipelineState();
1213
1214 context->m_ContextFeatures |= 1 << CONTEXT_FEATURE_MULTI_TARGET_RENDERING;
1215 context->m_ContextFeatures |= 1 << CONTEXT_FEATURE_TEXTURE_ARRAY;
1216 context->m_ContextFeatures |= 1 << CONTEXT_FEATURE_COMPUTE_SHADER;
1217 context->m_ContextFeatures |= 1 << CONTEXT_FEATURE_BLEND_EQUATION_MIN_MAX;
1218
1219#if defined (DM_GRAPHICS_WEBGPU2)
1220 const uint32_t webgpu_version = 2;
1221#else
1222 const uint32_t webgpu_version = 1;
1223#endif
1224
1225 dmLogInfo("WebGPU v%d", webgpu_version);
1226
1227 context->m_Instance = wgpuCreateInstance(nullptr);
1228
1229#if defined(DM_GRAPHICS_WEBGPU2)
1230 WGPURequestAdapterCallbackInfo requestAdapterCallbackInfo = WGPU_REQUEST_ADAPTER_CALLBACK_INFO_INIT;
1231 requestAdapterCallbackInfo.mode = WGPUCallbackMode_WaitAnyOnly;
1232 requestAdapterCallbackInfo.callback = instanceRequestAdapterCallback;
1233 requestAdapterCallbackInfo.userdata1 = context;
1234 const WGPUFuture future = wgpuInstanceRequestAdapter(context->m_Instance, NULL, requestAdapterCallbackInfo);
1235 {
1236 WGPUFutureWaitInfo waitInfo = { future, 0 };
1237 WGPUWaitStatus status = wgpuInstanceWaitAny(context->m_Instance, 1, &waitInfo, std::numeric_limits<uint64_t>::max());
1238 assert(waitInfo.completed);
1239 assert(waitInfo.future.id == future.id);
1240 assert(status == WGPUWaitStatus_Success);
1241 assert(context->m_InitComplete);
1242 (void)status;
1243 }
1244#else
1245 wgpuInstanceRequestAdapter(context->m_Instance, NULL, instanceRequestAdapterCallback, context);
1246#if defined(__EMSCRIPTEN__)
1247 while (!context->m_InitComplete)
1248 emscripten_sleep(100);
1249#endif
1250#endif
1251 context->m_SamplerCache.SetCapacity(32, 64);
1252 context->m_BindGroupCache.SetCapacity(32, 64);
1253 context->m_RenderPipelineCache.SetCapacity(32, 64);
1254 context->m_ComputePipelineCache.SetCapacity(32, 64);
1255 SetSwapInterval((HContext) context, params.m_SwapInterval);
1256

Callers 1

WebGPUNewContextFunction · 0.85

Calls 9

GetDefaultPipelineStateFunction · 0.85
WebGPUGetOrCreateSamplerFunction · 0.85
WebGPUNewTextureInternalFunction · 0.85
WebGPUSetTextureInternalFunction · 0.85
assertFunction · 0.50
GetWindowStateParamFunction · 0.50
maxFunction · 0.50
SetSwapIntervalFunction · 0.50
SetCapacityMethod · 0.45

Tested by

no test coverage detected