implement core branching logic for metal enumeration of physical devices
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
#include "gryphn_physical_device.h"
|
||||||
|
#include "instance/gryphn_instance.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
gnReturnCode gnEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices) {
|
||||||
|
return instance->dispatchTable.enumeratePhysicalDevices(instance, deviceCount, devices);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "gryphn_handle.h"
|
||||||
|
#include "gryphn_return_code.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
gnReturnCode gnEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices);
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define GN_HANDLE(type) typedef struct type##_t* type
|
#define GN_HANDLE(type) typedef struct type##_t* type
|
||||||
|
#define GN_IMPLEMENTATION_HANDLE(type) typedef void* type
|
||||||
|
|
||||||
GN_HANDLE(gnInstance);
|
GN_HANDLE(gnInstance);
|
||||||
|
GN_IMPLEMENTATION_HANDLE(gnPhysicalDevice);
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
#include "gryphn_handle.h"
|
#include "gryphn_handle.h"
|
||||||
|
|
||||||
typedef gnReturnCode (*PFN_gnDestroyInstance)(gnInstance);
|
typedef gnReturnCode (*PFN_gnDestroyInstance)(gnInstance);
|
||||||
|
typedef gnReturnCode (*PFN_enumeratePhysicalDevices)(gnInstance, uint32_t*, gnPhysicalDevice*);
|
||||||
|
|
||||||
|
|
||||||
typedef struct gnInstanceDispatchTable {
|
typedef struct gnInstanceDispatchTable {
|
||||||
PFN_gnDestroyInstance destroyInstance;
|
PFN_gnDestroyInstance destroyInstance;
|
||||||
|
PFN_enumeratePhysicalDevices enumeratePhysicalDevices;
|
||||||
} gnInstanceDispatchTable;
|
} gnInstanceDispatchTable;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
#include "gryphn_handle.h"
|
#include "gryphn_handle.h"
|
||||||
|
#include "metal_functions.h"
|
||||||
|
|
||||||
extern "C" uint32_t gnInternalIsApiSupported(gnVersion version) {
|
extern "C" uint32_t gnInternalIsApiSupported(gnVersion version) {
|
||||||
if (version != gnCreateVersion(1, 0, 0)) return 0;
|
if (version != gnCreateVersion(1, 0, 0)) return 0;
|
||||||
@@ -13,12 +14,11 @@ extern "C" uint32_t gnInternalIsApiSupported(gnVersion version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gnReturnCode destroyBackend(gnInstance instance) {
|
gnReturnCode destroyBackend(gnInstance instance) {
|
||||||
printf("Calling destroy instance");
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" gnReturnCode initBackend(gnInstance instance, gnInstanceCreateInfo* info) {
|
extern "C" gnReturnCode initBackend(gnInstance instance, gnInstanceCreateInfo* info) {
|
||||||
printf("calling init instance\n");
|
|
||||||
instance->dispatchTable.destroyInstance = destroyBackend;
|
instance->dispatchTable.destroyInstance = destroyBackend;
|
||||||
|
instance->dispatchTable.enumeratePhysicalDevices = metalEnumeratePhysicalDevices;
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#include "metal_functions.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
gnReturnCode metalEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices) {
|
||||||
|
*deviceCount = 0;
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
c
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "gryphn_handle.h"
|
||||||
|
#include "gryphn_return_code.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
|
||||||
|
gnReturnCode metalEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices);
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#include "GryphnLoader/src/instance/gryphn_instance.h"
|
#include "GryphnLoader/src/instance/gryphn_instance.h"
|
||||||
|
#include "GryphnLoader/src/device/gryphn_physical_device.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -40,9 +40,19 @@ void createInstance() {
|
|||||||
free(backends);
|
free(backends);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void createDevice() {
|
||||||
|
uint32_t physicalDeviceCount;
|
||||||
|
CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, nullptr));
|
||||||
|
gnPhysicalDevice* devices = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * physicalDeviceCount);
|
||||||
|
CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, devices));
|
||||||
|
|
||||||
|
std::cout << "Found " << physicalDeviceCount << " physical devices:\n";
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
createInstance();
|
createInstance();
|
||||||
|
createDevice();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "Caught Exception: " << e.what() << "\n";
|
std::cerr << "Caught Exception: " << e.what() << "\n";
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user