query metal devices
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
gryphnInstanceFunctionLayers metalLoadAPILayer(void) {
|
gryphnInstanceFunctionLayers metalLoadAPILayer(void) {
|
||||||
return (gryphnInstanceFunctionLayers) {
|
return (gryphnInstanceFunctionLayers) {
|
||||||
.createInstance = metalCreateInstance,
|
.createInstance = metalCreateInstance,
|
||||||
|
.queryDevices = metalQueryDevices,
|
||||||
.destroyInstance = metalDestroyInstance,
|
.destroyInstance = metalDestroyInstance,
|
||||||
.next = NULL
|
.next = NULL
|
||||||
};
|
};
|
||||||
@@ -13,7 +14,6 @@ gryphnInstanceFunctionLayers metalLoadAPILayer(void) {
|
|||||||
|
|
||||||
gnInstanceFunctions loadMetalInstanceFunctions(void) {
|
gnInstanceFunctions loadMetalInstanceFunctions(void) {
|
||||||
return (gnInstanceFunctions){
|
return (gnInstanceFunctions){
|
||||||
._gnGetPhysicalDevices = getMetalDevices,
|
|
||||||
._gnPhysicalDeviceCanPresentToSurface = metalCanDevicePresent,
|
._gnPhysicalDeviceCanPresentToSurface = metalCanDevicePresent,
|
||||||
._gnCreateOutputDevice = createMetalOutputDevice,
|
._gnCreateOutputDevice = createMetalOutputDevice,
|
||||||
._gnDestroyOutputDevice = destroyMetalOutputDevice,
|
._gnDestroyOutputDevice = destroyMetalOutputDevice,
|
||||||
|
@@ -3,45 +3,41 @@
|
|||||||
#include "metal_output_devices.h"
|
#include "metal_output_devices.h"
|
||||||
#include "window_surface/gryphn_surface.h"
|
#include "window_surface/gryphn_surface.h"
|
||||||
|
|
||||||
gnPhysicalDevice* getMetalDevices(gnInstanceHandle instance, uint32_t* deviceCount) {
|
// gnPhysicalDevice* getMetalDevices(gnInstanceHandle instance, uint32_t* deviceCount) {
|
||||||
if (instance == GN_NULL_HANDLE) return NULL;
|
// if (instance == GN_NULL_HANDLE) return NULL;
|
||||||
|
|
||||||
NSArray *devices = MTLCopyAllDevices();
|
// NSArray *devices = MTLCopyAllDevices();
|
||||||
*deviceCount = (uint32_t)[devices count];
|
// *deviceCount = (uint32_t)[devices count];
|
||||||
gnPhysicalDevice* devicesList = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount);
|
// gnPhysicalDevice* devicesList = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount);
|
||||||
for (uint32_t i = 0; i < *deviceCount; i++) {
|
// for (uint32_t i = 0; i < *deviceCount; i++) {
|
||||||
devicesList[i] = malloc(sizeof(gnPhysicalOutputDevice_t));
|
// devicesList[i] = (uint64_t)[devices objectAtIndex:0];
|
||||||
devicesList[i]->physicalDevice = malloc(sizeof(gnPlatformPhysicalDevice));
|
// mtlDevice device = (mtlDevice)devicesList[i];
|
||||||
devicesList[i]->physicalDevice->device = [devices objectAtIndex:0];
|
|
||||||
|
|
||||||
|
// devicesList[i]->properties.name = gnCreateString([[device name] cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||||
|
// MTLDeviceLocation deviceLocation = device.locationNumber;
|
||||||
|
// if (deviceLocation == MTLDeviceLocationBuiltIn)
|
||||||
|
// devicesList[i]->properties.deviceType = GN_INTEGRATED_DEVICE;
|
||||||
|
// else if (deviceLocation == MTLDeviceLocationSlot)
|
||||||
|
// devicesList[i]->properties.deviceType = GN_DEDICATED_DEVICE;
|
||||||
|
// else if (deviceLocation == MTLDeviceLocationExternal)
|
||||||
|
// devicesList[i]->properties.deviceType = GN_EXTERNAL_DEVICE;
|
||||||
|
|
||||||
id<MTLDevice> device = [devices objectAtIndex:0];
|
// devicesList[i]->features.maxColorSamples = GN_SAMPLE_BIT_1;
|
||||||
devicesList[i]->properties.name = gnCreateString([[device name] cStringUsingEncoding:NSUTF8StringEncoding]);
|
// if ([device supportsTextureSampleCount:2]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_2; } else {}
|
||||||
MTLDeviceLocation deviceLocation = device.locationNumber;
|
// if ([device supportsTextureSampleCount:4]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_4; } else {}
|
||||||
if (deviceLocation == MTLDeviceLocationBuiltIn)
|
// if ([device supportsTextureSampleCount:8]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_8; } else {}
|
||||||
devicesList[i]->properties.deviceType = GN_INTEGRATED_DEVICE;
|
// if ([device supportsTextureSampleCount:16]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_16; } else {}
|
||||||
else if (deviceLocation == MTLDeviceLocationSlot)
|
// if ([device supportsTextureSampleCount:32]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_32; } else {}
|
||||||
devicesList[i]->properties.deviceType = GN_DEDICATED_DEVICE;
|
// devicesList[i]->features.maxDepthSamples = devicesList[i]->features.maxColorSamples;
|
||||||
else if (deviceLocation == MTLDeviceLocationExternal)
|
|
||||||
devicesList[i]->properties.deviceType = GN_EXTERNAL_DEVICE;
|
|
||||||
|
|
||||||
devicesList[i]->features.maxColorSamples = GN_SAMPLE_BIT_1;
|
// devicesList[i]->features.maxMemoryAllocations = 0x40000000;
|
||||||
if ([device supportsTextureSampleCount:2]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_2; } else {}
|
// devicesList[i]->features.maxPushConstantSize = 4096;
|
||||||
if ([device supportsTextureSampleCount:4]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_4; } else {}
|
// }
|
||||||
if ([device supportsTextureSampleCount:8]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_8; } else {}
|
// [devices release];
|
||||||
if ([device supportsTextureSampleCount:16]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_16; } else {}
|
// return devicesList;
|
||||||
if ([device supportsTextureSampleCount:32]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_32; } else {}
|
// }
|
||||||
devicesList[i]->features.maxDepthSamples = devicesList[i]->features.maxColorSamples;
|
|
||||||
|
|
||||||
devicesList[i]->features.maxMemoryAllocations = 0x40000000;
|
|
||||||
devicesList[i]->features.maxPushConstantSize = 4096;
|
|
||||||
}
|
|
||||||
[devices release];
|
|
||||||
return devicesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnBool metalCanDevicePresent(gnPhysicalDevice device, gnWindowSurface windowSurface) {
|
gnBool metalCanDevicePresent(gnPhysicalDevice device, gnWindowSurface windowSurface) {
|
||||||
if (device == GN_NULL_HANDLE || windowSurface == GN_NULL_HANDLE) return GN_FALSE;
|
if (device == GN_NULL_HANDLE || windowSurface == GN_NULL_HANDLE) return GN_FALSE;
|
||||||
|
|
||||||
return GN_TRUE; // I belive that a window should always be able to present to a surface in metal
|
return GN_TRUE; // I belive that a window should always be able to present to a surface in metal
|
||||||
}
|
}
|
||||||
|
@@ -8,4 +8,5 @@ typedef struct gnPlatformInstance_t {
|
|||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
|
gnReturnCode metalQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices);
|
||||||
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
|
@@ -8,6 +8,15 @@ gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo
|
|||||||
instance->instance = allocators->malloc(sizeof(gnPlatformInstance), allocators->userData);
|
instance->instance = allocators->malloc(sizeof(gnPlatformInstance), allocators->userData);
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
gnReturnCode metalQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices) {
|
||||||
|
if (instance == GN_NULL_HANDLE) return NULL;
|
||||||
|
NSArray *metalDevices = MTLCopyAllDevices();
|
||||||
|
*count = (uint32_t)[metalDevices count];
|
||||||
|
if (devices == NULL) return GN_SUCCESS;
|
||||||
|
for (int i = 0; i < *count; i++)
|
||||||
|
devices[i] = (uint64_t)metalDevices[i];
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||||
if (next != NULL) return;
|
if (next != NULL) return;
|
||||||
allocators->free(instance->instance, allocators->userData);
|
allocators->free(instance->instance, allocators->userData);
|
||||||
|
@@ -25,7 +25,6 @@ typedef gnReturnCode (*PFN_gnInstanceQueryDevices)(gnInstanceHandle, uint32_t*,
|
|||||||
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle, gryphnInstanceFunctionLayers*, gnAllocators*);
|
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle, gryphnInstanceFunctionLayers*, gnAllocators*);
|
||||||
|
|
||||||
typedef struct gnInstanceFunctions {
|
typedef struct gnInstanceFunctions {
|
||||||
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
|
||||||
gnBool (*_gnPhysicalDeviceCanPresentToSurface)(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
gnBool (*_gnPhysicalDeviceCanPresentToSurface)(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
||||||
|
|
||||||
gnReturnCode (*_gnCreateOutputDevice)(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
|
gnReturnCode (*_gnCreateOutputDevice)(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
|
||||||
|
Reference in New Issue
Block a user