get physical device properties

This commit is contained in:
Gregory Wells
2026-05-24 20:19:22 -04:00
parent ebaf4fde0a
commit b0c36a6bea
4 changed files with 38 additions and 10 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ gnReturnCode initBackend(gnInstance instance, gnInstanceCreateInfo* info) {
instance->dispatchTable.destroyInstance = destroyBackend;
instance->dispatchTable.enumeratePhysicalDevices = vulkanEnumeratePhysicalDevices;
// instance->dispatchTable.getPhysicalDeviceProperties = NULL;
instance->dispatchTable.getPhysicalDeviceProperties = vulkanGetPhysicalDeviceProperties;
// instance->dispatchTable.createDevice = NULL;
// for (int i = 0; i < info->enabledExtensionCount; i++) {
@@ -4,8 +4,20 @@
#include "vulkan_helpers.h"
#include "instance/gryphn_instance.h"
#include "device/gryphn_physical_device.h"
#include <string.h>
#include <vulkan/vulkan_core.h>
gnPhysicalDeviceType vulkanDeviceTypeToGryphnDeviceType(VkPhysicalDeviceType type) {
switch (type) {
case VK_PHYSICAL_DEVICE_TYPE_OTHER: return GN_PHYSICAL_DEVICE_TYPE_OTHER;
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: return GN_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: return GN_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: return GN_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
case VK_PHYSICAL_DEVICE_TYPE_CPU: return GN_PHYSICAL_DEVICE_TYPE_CPU;
case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: return GN_PHYSICAL_DEVICE_TYPE_OTHER;
}
}
gnReturnCode vulkanEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices) {
if (devices == NULL) {
vkEnumeratePhysicalDevices(instance->internalData, deviceCount, NULL);
@@ -29,3 +41,17 @@ gnReturnCode vulkanEnumeratePhysicalDevices(gnInstance instance, uint32_t* devic
free(vulkanDevices);
return GN_SUCCESS;
}
gnReturnCode vulkanGetPhysicalDeviceProperties(gnPhysicalDevice device, gnPhysicalDeviceProperties* properties) {
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device->internalData, &deviceProperties);
*properties = (gnPhysicalDeviceProperties){
.apiVersion = deviceProperties.apiVersion,
.vendorID = deviceProperties.vendorID,
.deviceID = deviceProperties.deviceID,
.deviceType = vulkanDeviceTypeToGryphnDeviceType(deviceProperties.deviceType),
};
strcpy(properties->deviceName, deviceProperties.deviceName);
return GN_SUCCESS;
}
@@ -2,5 +2,7 @@
#include "stdint.h"
#include "gryphn_handle.h"
#include "gryphn_return_code.h"
#include "device/gryphn_physical_device.h"
gnReturnCode vulkanEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices);
gnReturnCode vulkanGetPhysicalDeviceProperties(gnPhysicalDevice device, gnPhysicalDeviceProperties* properties);
+9 -9
View File
@@ -32,7 +32,7 @@ void createInstance() {
CHECK(gnGetAvaliableBackends(version, &backendCount, backends));
const char* extensions[2] = {
"GN_EXT_surface",
"GN_EXT_surface_cocoa"
"GN_EXT_surface_xlib"
};
gnInstanceCreateInfo createInfo = {
@@ -55,15 +55,15 @@ void createInstance() {
void createDevice() {
uint32_t physicalDeviceCount;
CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, nullptr));
// gnPhysicalDevice* devices = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * physicalDeviceCount);
// CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, devices));
gnPhysicalDevice* devices = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * physicalDeviceCount);
CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, devices));
// std::cout << "Found " << physicalDeviceCount << " physical devices:\n";
// for (int i = 0; i < physicalDeviceCount; i++) {
// gnPhysicalDeviceProperties properties;
// gnGetPhysicalDeviceProperties(devices[i], &properties);
// std::cout << "Name: " << properties.deviceName << "\n";
// }
std::cout << "Found " << physicalDeviceCount << " physical devices:\n";
for (int i = 0; i < physicalDeviceCount; i++) {
gnPhysicalDeviceProperties properties;
gnGetPhysicalDeviceProperties(devices[i], &properties);
std::cout << "Name: " << properties.deviceName << "\n";
}
// pysicalDevice = devices[0];