MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Get

Method Get

Source/Engine/GraphicsDevice/WebGPU/GPUPipelineStateWebGPU.cpp:421–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421WGPUBindGroup GPUBindGroupCacheWebGPU::Get(WGPUDevice device, GPUBindGroupKeyWebGPU& key, const StringAnsiView& debugName, uint64 gcFrames)
422{
423#if WEBGPU_LOG_BIND_GROUPS
424#ifdef WEBGPU_LOG_PSO_NAME
425 const bool log = debugName.Contains(WEBGPU_LOG_PSO_NAME);
426#else
427 const bool log = true;
428#endif
429#endif
430
431 // Generate a hash for the key
432 key.LastFrameUsed = Engine::FrameCount;
433 key.Hash = Crc::MemCrc32(&key.Entries, key.EntriesCount * sizeof(WGPUBindGroupEntry));
434 CombineHash(key.Hash, GetHash(key.EntriesCount));
435 CombineHash(key.Hash, GetHash(key.Layout));
436 CombineHash(key.Hash, Crc::MemCrc32(&key.Versions, key.EntriesCount * sizeof(uint8)));
437
438 // Lookup for existing bind group
439 WGPUBindGroup bindGroup;
440#if WEBGPU_CACHE_BIND_GROUPS
441 auto found = _bindGroups.Find(key);
442 if (found.IsNotEnd())
443 {
444 // Get cached bind group and update the last usage frame
445 bindGroup = found->Value;
446 found->Key.LastFrameUsed = key.LastFrameUsed;
447
448 // Periodically remove old bind groups (unused for some time)
449 if (key.LastFrameUsed - _lastFrameBindGroupsGC > gcFrames * 2)
450 {
451 _lastFrameBindGroupsGC = key.LastFrameUsed;
452 int32 freed = 0;
453 for (auto it = _bindGroups.Begin(); it.IsNotEnd(); ++it)
454 {
455 if (key.LastFrameUsed - it->Key.LastFrameUsed > gcFrames)
456 {
457 freed++;
458 wgpuBindGroupRelease(it->Value);
459 _bindGroups.Remove(it);
460 }
461 }
462#if WEBGPU_LOG_BIND_GROUPS
463 if (freed > 0 && log)
464 LOG(Info, "[WebGPU] Removed {} old entries from '{}'", freed, String(debugName));
465#endif
466 }
467
468 return bindGroup;
469 }
470#endif
471 PROFILE_CPU();
472 PROFILE_MEM(GraphicsShaders);
473#if GPU_ENABLE_RESOURCE_NAMING
474 ZoneText(debugName.Get(), debugName.Length());
475#endif
476#if WEBGPU_LOG_BIND_GROUPS
477 if (log)
478 LOG(Info, "[WebGPU] GetBindGroup: '{}', hash: {}", String(debugName), key.Hash);

Callers 15

ExecuteMethod · 0.45
UpdateDescriptorSetsMethod · 0.45
OnDrawCallMethod · 0.45
BindMethod · 0.45
SetObjectNameMethod · 0.45
SubmitMethod · 0.45
SubmitActiveCmdBufferMethod · 0.45

Calls 13

CombineHashFunction · 0.85
MemoryCompareFunction · 0.85
GetHashFunction · 0.70
StringClass · 0.50
ContainsMethod · 0.45
FindMethod · 0.45
IsNotEndMethod · 0.45
BeginMethod · 0.45
RemoveMethod · 0.45
LengthMethod · 0.45
CountMethod · 0.45
CapacityMethod · 0.45

Tested by

no test coverage detected