Skip to content

Commit 2b20ed8

Browse files
committed
GPU: update JSON result structure; fix segfault and memleaks
1 parent ae3c15b commit 2b20ed8

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/detection/gpu/gpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const char* detectByOpenGL(FFlist* gpus)
5555
ffStrbufInitMove(&gpu->name, &result.renderer);
5656
ffStrbufInit(&gpu->driver);
5757
ffStrbufInitF(&gpu->platformApi, "OpenGL %s", result.version.chars);
58+
ffStrbufInit(&gpu->memoryType);
5859
gpu->index = FF_GPU_INDEX_UNSET;
5960
gpu->temperature = FF_GPU_TEMP_UNSET;
6061
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;

src/detection/opencl/opencl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
9292
ffStrbufInit(&gpu->vendor);
9393
ffStrbufInit(&gpu->driver);
9494
ffStrbufInit(&gpu->platformApi);
95+
ffStrbufInit(&gpu->memoryType);
9596
gpu->index = FF_GPU_INDEX_UNSET;
9697
gpu->temperature = FF_GPU_TEMP_UNSET;
9798
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;

src/detection/vulkan/vulkan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static const char* detectVulkan(FFVulkanResult* result)
220220
gpu->type = physicalDeviceProperties.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
221221
ffStrbufInitS(&gpu->vendor, ffGPUGetVendorString(physicalDeviceProperties.properties.vendorID));
222222
ffStrbufInitS(&gpu->driver, driverProperties.driverInfo);
223+
ffStrbufInit(&gpu->memoryType);
223224

224225
VkPhysicalDeviceMemoryProperties memoryProperties = {};
225226
ffvkGetPhysicalDeviceMemoryProperties(physicalDevices[i], &memoryProperties);

src/modules/gpu/gpu.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ void ffPrintGPU(FFGPUOptions* options)
194194
ffStrbufDestroy(&gpu->name);
195195
ffStrbufDestroy(&gpu->driver);
196196
ffStrbufDestroy(&gpu->platformApi);
197+
ffStrbufDestroy(&gpu->memoryType);
197198
}
198199
}
199200

@@ -399,9 +400,6 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
399400
else
400401
yyjson_mut_obj_add_null(doc, dedicatedObj, "used");
401402

402-
yyjson_mut_obj_add_strbuf(doc, obj, "driver", &gpu->driver);
403-
yyjson_mut_obj_add_strbuf(doc, obj, "name", &gpu->name);
404-
405403
yyjson_mut_val* sharedObj = yyjson_mut_obj_add_obj(doc, memoryObj, "shared");
406404
if (gpu->shared.total != FF_GPU_VMEM_SIZE_UNSET)
407405
yyjson_mut_obj_add_uint(doc, sharedObj, "total", gpu->shared.total);
@@ -412,7 +410,13 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
412410
else
413411
yyjson_mut_obj_add_null(doc, sharedObj, "used");
414412

415-
yyjson_mut_obj_add_strbuf(doc, obj, "memoryType", &gpu->memoryType);
413+
if (gpu->memoryType.length)
414+
yyjson_mut_obj_add_strbuf(doc, memoryObj, "type", &gpu->memoryType);
415+
else
416+
yyjson_mut_obj_add_null(doc, memoryObj, "type");
417+
418+
yyjson_mut_obj_add_strbuf(doc, obj, "driver", &gpu->driver);
419+
yyjson_mut_obj_add_strbuf(doc, obj, "name", &gpu->name);
416420

417421
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
418422
yyjson_mut_obj_add_real(doc, obj, "temperature", gpu->temperature);
@@ -443,6 +447,7 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
443447
ffStrbufDestroy(&gpu->name);
444448
ffStrbufDestroy(&gpu->driver);
445449
ffStrbufDestroy(&gpu->platformApi);
450+
ffStrbufDestroy(&gpu->memoryType);
446451
}
447452
}
448453

0 commit comments

Comments
 (0)