load all instance functions
This commit is contained in:
@@ -1,15 +1,18 @@
|
|||||||
#include "metal_loader.h"
|
#include "metal_loader.h"
|
||||||
|
#include "instance/metal_instance.h"
|
||||||
|
#include "surface/metal_surface.h"
|
||||||
|
#include "devices/metal_output_devices.h"
|
||||||
|
|
||||||
gnInstanceFunctions loadMetalInstanceFunctions() {
|
gnInstanceFunctions loadMetalInstanceFunctions() {
|
||||||
return (gnInstanceFunctions){
|
return (gnInstanceFunctions){
|
||||||
._gnCreateInstance = NULL,
|
._gnCreateInstance = createMetalInstance,
|
||||||
._gnDestroyInstance = NULL,
|
._gnDestroyInstance = destroyMetalInstance,
|
||||||
._gnGetPhysicalDevices = NULL,
|
._gnGetPhysicalDevices = getMetalDevices,
|
||||||
._gnQueueCanPresentToSurface = NULL,
|
._gnQueueCanPresentToSurface = metalCanQueuePresentToSurface,
|
||||||
._gnCreateOutputDevice = NULL,
|
._gnCreateOutputDevice = createMetalOutputDevice,
|
||||||
._gnDestroyOutputDevice = NULL,
|
._gnDestroyOutputDevice = destroyMetalOutputDevice,
|
||||||
._gnCreateMacOSWindowSurface = NULL,
|
._gnCreateMacOSWindowSurface = createMetalSurface,
|
||||||
._gnDestroyWindowSurface = NULL,
|
._gnDestroyWindowSurface = destroyMetalWindowSurface,
|
||||||
._gnGetSurfaceDetails = NULL
|
._gnGetSurfaceDetails = getMetalSurfaceDetails
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
#include <debugger/gryphn_debugger.h>
|
#include <debugger/gryphn_debugger.h>
|
||||||
|
|
||||||
gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
|
gnReturnCode createMetalOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
|
||||||
outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
|
outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
|
||||||
outputDevice->outputDevice->device = deviceInfo.physicalDevice.physicalDevice->device.retain;
|
outputDevice->outputDevice->device = deviceInfo.physicalDevice.physicalDevice->device.retain;
|
||||||
outputDevice->outputDevice->transferQueue = outputDevice->outputDevice->device.newCommandQueue;
|
outputDevice->outputDevice->transferQueue = outputDevice->outputDevice->device.newCommandQueue;
|
||||||
@@ -18,11 +18,11 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanc
|
|||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnWaitForDeviceFn(gnOutputDeviceHandle device) {
|
void waitForMetalDevice(gnOutputDeviceHandle device) {
|
||||||
[device->outputDevice->executingCommandBuffer waitUntilCompleted];
|
[device->outputDevice->executingCommandBuffer waitUntilCompleted];
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyOutputDeviceFn(gnOutputDeviceHandle device) {
|
void destroyMetalOutputDevice(gnOutputDeviceHandle device) {
|
||||||
// for (int i = 0; i < device->outputDevice->queueCount; i++) {
|
// for (int i = 0; i < device->outputDevice->queueCount; i++) {
|
||||||
// [device->outputDevice->queues[i] release];
|
// [device->outputDevice->queues[i] release];
|
||||||
// }
|
// }
|
||||||
|
@@ -16,3 +16,10 @@ struct gnPlatformOutputDevice_t {
|
|||||||
id<MTLCommandQueue> transferQueue;
|
id<MTLCommandQueue> transferQueue;
|
||||||
// id<MTLRenderPipelineState> framebuffer;
|
// id<MTLRenderPipelineState> framebuffer;
|
||||||
} gnPlatformOutputDevice;
|
} gnPlatformOutputDevice;
|
||||||
|
|
||||||
|
gnPhysicalDevice* getMetalDevices(gnInstanceHandle instance, uint32_t* deviceCount);
|
||||||
|
gnBool metalCanQueuePresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurface windowSurface);
|
||||||
|
|
||||||
|
gnReturnCode createMetalOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo);
|
||||||
|
void waitForMetalDevice(gnOutputDeviceHandle device);
|
||||||
|
void destroyMetalOutputDevice(gnOutputDeviceHandle device);
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
#include "metal_output_devices.h"
|
#include "metal_output_devices.h"
|
||||||
#include "window_surface/gryphn_surface.h"
|
#include "window_surface/gryphn_surface.h"
|
||||||
|
|
||||||
gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* deviceCount) {
|
gnPhysicalDevice* getMetalDevices(gnInstanceHandle instance, uint32_t* deviceCount) {
|
||||||
NSArray *devices = MTLCopyAllDevices();
|
NSArray *devices = MTLCopyAllDevices();
|
||||||
*deviceCount = [devices count];
|
*deviceCount = [devices count];
|
||||||
gnPhysicalDevice* devicesList = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount);
|
gnPhysicalDevice* devicesList = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount);
|
||||||
@@ -34,6 +34,6 @@ gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* de
|
|||||||
return devicesList;
|
return devicesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
gnBool gnQueueCanPresentToSurfaceFn(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurface windowSurface) {
|
gnBool metalCanQueuePresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurface windowSurface) {
|
||||||
return gnTrue; // I belive that a window should always be able to present to a surface in metal
|
return gnTrue; // I belive that a window should always be able to present to a surface in metal
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Metal/MTLRenderPipeline.h>
|
#include <Metal/MTLRenderPipeline.h>
|
||||||
#include <AppKit/AppKit.h>
|
#include <AppKit/AppKit.h>
|
||||||
|
#include "core/src/instance/gryphn_instance.h"
|
||||||
|
|
||||||
typedef struct gnPlatformInstance_t {
|
typedef struct gnPlatformInstance_t {
|
||||||
NSView* metalContentView;
|
NSView* metalContentView;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
|
gnReturnCode createMetalInstance(gnInstanceHandle instance, gnInstanceInfo instanceInfo);
|
||||||
|
void destroyMetalInstance(gnInstance instance);
|
||||||
|
@@ -1,14 +1,10 @@
|
|||||||
#include <gryphn/gryphn.h>
|
|
||||||
#include <gryphn/gryphn_utils.h>
|
|
||||||
#include "metal_instance.h"
|
#include "metal_instance.h"
|
||||||
// #include "bridge/metal_bridge.h"
|
|
||||||
|
|
||||||
|
// metal instances are kinda useless
|
||||||
gnReturnCode gnCreateInstanceFn(gnInstanceHandle instance, gnInstanceInfo instanceInfo) {
|
gnReturnCode createMetalInstance(gnInstanceHandle instance, gnInstanceInfo instanceInfo) {
|
||||||
if (instance->instance == NULL) instance->instance = malloc(sizeof(gnPlatformInstance));
|
if (instance->instance == NULL) instance->instance = malloc(sizeof(gnPlatformInstance));
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
void destroyMetalInstance(gnInstance instance) {
|
||||||
void gnDestroyInstanceFn(gnInstanceHandle instance) {
|
|
||||||
free(instance->instance);
|
free(instance->instance);
|
||||||
}
|
}
|
||||||
|
@@ -9,3 +9,7 @@ typedef struct gnPlatformWindowSurface_t {
|
|||||||
|
|
||||||
MTLPixelFormat mtlGryphnFormatToVulkanFormat(gnImageFormat format);
|
MTLPixelFormat mtlGryphnFormatToVulkanFormat(gnImageFormat format);
|
||||||
CGColorSpaceRef mtlGryphnColorSpaceToVulkanColorSpace(gnColorSpace colorSpace);
|
CGColorSpaceRef mtlGryphnColorSpaceToVulkanColorSpace(gnColorSpace colorSpace);
|
||||||
|
|
||||||
|
gnReturnCode createMetalSurface(gnWindowSurface windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo);
|
||||||
|
gnSurfaceDetails getMetalSurfaceDetails(gnWindowSurface windowSurface, gnPhysicalDevice device);
|
||||||
|
void destroyMetalWindowSurface(gnWindowSurface windowSurface);
|
||||||
|
@@ -8,17 +8,17 @@
|
|||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
#import <CoreGraphics/CoreGraphics.h>
|
#import <CoreGraphics/CoreGraphics.h>
|
||||||
|
|
||||||
gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) {
|
gnReturnCode createMetalSurface(gnWindowSurface windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) {
|
||||||
windowSurface->windowSurface = malloc(sizeof(gnPlatformWindowSurface));
|
windowSurface->windowSurface = malloc(sizeof(gnPlatformWindowSurface));
|
||||||
windowSurface->windowSurface->layer = createInfo.layer;
|
windowSurface->windowSurface->layer = createInfo.layer;
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyWindowSurfaceFn(struct gnWindowSurface_t *windowSurface) {
|
void destroyMetalWindowSurface(gnWindowSurface windowSurface) {
|
||||||
free(windowSurface->windowSurface);
|
free(windowSurface->windowSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
gnSurfaceDetails gnGetSurfaceDetailsFn(
|
gnSurfaceDetails getMetalSurfaceDetails(
|
||||||
gnWindowSurface windowSurface, gnPhysicalDevice device
|
gnWindowSurface windowSurface, gnPhysicalDevice device
|
||||||
) {
|
) {
|
||||||
gnSurfaceDetails surfaceDetails;
|
gnSurfaceDetails surfaceDetails;
|
||||||
|
@@ -73,7 +73,13 @@ void checkDestroyOutputDevice(gnOutputDeviceHandle device) {
|
|||||||
|
|
||||||
gnReturnCode checkCreateSurfaceMacOS(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) {
|
gnReturnCode checkCreateSurfaceMacOS(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) {
|
||||||
loaderLayer* nextLayer = loaderGetNextLayer(instance);
|
loaderLayer* nextLayer = loaderGetNextLayer(instance);
|
||||||
if (nextLayer->instanceFunctions._gnCreateMacOSWindowSurface == NULL) { return GN_FAILED_TO_LOAD_FUNCTION; }
|
if (nextLayer->instanceFunctions._gnCreateMacOSWindowSurface == NULL) {
|
||||||
|
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||||
|
.message = gnCreateString("Failed to load create window surface function")
|
||||||
|
});
|
||||||
|
resetLayer(instance);
|
||||||
|
return GN_FAILED_TO_LOAD_FUNCTION;
|
||||||
|
}
|
||||||
return nextLayer->instanceFunctions._gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
|
return nextLayer->instanceFunctions._gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user