MCPcopy Create free account
hub / github.com/Niko1221/Strata / gpu_shared_memory_budget

Function gpu_shared_memory_budget

engine/src/platform/memory.cpp:112–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112bool gpu_shared_memory_budget(const void* luid, uint64_t& budget, uint64_t& usage, std::string& why) {
113 budget = usage = 0;
114 // dxgi.dll is loaded when asked, not linked: a start that never needs this keeps the imports it had
115 HMODULE dxgi = LoadLibraryA("dxgi.dll");
116 if (dxgi == nullptr) { why = "dxgi.dll not found"; return false; }
117 using CreateFactory = HRESULT(WINAPI*)(REFIID, void**);
118 const auto create = (CreateFactory) (void*) GetProcAddress(dxgi, "CreateDXGIFactory1");
119 IDXGIFactory1* factory = nullptr;
120 if (create == nullptr || FAILED(create(__uuidof(IDXGIFactory1), (void**) &factory)) || factory == nullptr) {
121 why = "CreateDXGIFactory1 failed";
122 FreeLibrary(dxgi);
123 return false;
124 }
125 bool ok = false;
126 why = "no DXGI adapter has the CUDA device's LUID";
127 for (UINT i = 0; !ok; ++i) {
128 IDXGIAdapter1* a = nullptr;
129 if (factory->EnumAdapters1(i, &a) == DXGI_ERROR_NOT_FOUND || a == nullptr) break;
130 DXGI_ADAPTER_DESC1 d{};
131 if (SUCCEEDED(a->GetDesc1(&d)) && std::memcmp(&d.AdapterLuid, luid, sizeof d.AdapterLuid) == 0) {
132 IDXGIAdapter3* a3 = nullptr;
133 DXGI_QUERY_VIDEO_MEMORY_INFO info{};
134 if (SUCCEEDED(a->QueryInterface(__uuidof(IDXGIAdapter3), (void**) &a3)) && a3 != nullptr &&
135 SUCCEEDED(a3->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info))) {
136 budget = info.Budget;
137 usage = info.CurrentUsage;
138 ok = budget > 0;
139 why = ok ? "" : "the adapter reports no shared-memory budget";
140 } else {
141 why = "QueryVideoMemoryInfo failed";
142 }
143 if (a3 != nullptr) a3->Release();
144 a->Release();
145 break;
146 }
147 a->Release();
148 }
149 factory->Release();
150 FreeLibrary(dxgi);
151 return ok;
152}
153
154uint64_t total_physical_memory() {
155 MEMORYSTATUSEX ms{};

Callers 1

pin_cache_complementMethod · 0.85

Calls 1

createFunction · 0.50

Tested by

no test coverage detected