-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: apple support #89
Draft
pollend
wants to merge
34
commits into
NVIDIAGameWorks:main
Choose a base branch
from
pollend:feature/apple-metal-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
7b8f156
feat: apple support
pollend 555ef0a
feat: add templte classes
pollend 12332e5
feat: add command queue mtl
pollend b6f1b07
add ds_store
pollend e640750
feat: update commanQueuMTL
pollend b0da08f
feat: add conversion and start texture
pollend a5a013d
feat: add more to api
pollend 29d0b72
feat: fix build
pollend 874bfaf
feat: add graphics queu
pollend e100cb2
feat: add interface
pollend ebb6843
feat: add descriptor
pollend f2ef030
fix compiling errors
pollend 5013f21
feat: start on command buffer logic
pollend b841503
add command buffer type
pollend 07e558b
start working on command buffer
pollend 322c8e9
feat: begin shader load logic
pollend 8e3d1e1
fix compiling errors
pollend 08cc6e2
feat: cleanup
pollend 7cd0c47
feat: fix compiling errors
pollend 2889d1d
feat: update desciprot and textureo
pollend c23acd8
feat: add command buffer impl progress
pollend 55a0f41
feat: add memory mtl
pollend 16e9e68
feat: more progress
pollend 6e71837
feat: add descriptor binding logic
pollend 4389b1d
feat: more progress with CommandBufferMTL
pollend b634abf
feat: progress command buffer logic
pollend cbe3d8e
feat: implement command buffer impl
pollend 722501a
feat: add swapchain
pollend fdac99d
feat: add alloc Buffer Desc
pollend 89637d6
feat: add more methods to implMTL
pollend ae69716
feat: add missing impl
pollend e757b6e
feat: add Creation logic
pollend 645f67d
feat: fix formats
pollend 2b43eb3
feat: address compiling issues
pollend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# apple | ||
.DS_Store | ||
|
||
# cmake | ||
CMakeFiles/ | ||
.cmake/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// © 2021 NVIDIA Corporation | ||
|
||
#pragma once | ||
|
||
#include "NRIMacro.h" | ||
#include "NRIDeviceCreation.h" | ||
|
||
|
||
NriNamespaceBegin | ||
|
||
|
||
typedef void* MTLHeap; | ||
typedef void* MTLDeviceHandle; // id<MTLDevice> | ||
typedef void* MTLBufferHandle; // id<MTLHeap> | ||
typedef void* MTLTextureHandle; | ||
|
||
typedef uint32_t MTLEnum; | ||
|
||
NriStruct(DeviceCreationMTLDesc) | ||
{ | ||
bool enableNRIValidation; | ||
MTLDeviceHandle MtlDevice; | ||
}; | ||
|
||
NriStruct(CommandBufferMTLDesc) | ||
{ | ||
|
||
}; | ||
|
||
NriStruct(BufferMTLDesc) | ||
{ | ||
MTLBufferHandle buffer; | ||
void* mappedMemory; | ||
//MTLResourceOptions options; | ||
}; | ||
|
||
NriStruct(TextureMTLDesc) | ||
{ | ||
MTLTextureHandle mtlTexture; | ||
MTLEnum textureType; | ||
MTLEnum pixelFormat; | ||
Nri(Dim_t) width; | ||
Nri(Dim_t) height; | ||
Nri(Dim_t) depth; | ||
Nri(Mip_t) mipNum; | ||
Nri(Dim_t) layerNum; | ||
Nri(Sample_t) sampleNum; | ||
//MTLTextureDescriptor* descriptor; | ||
}; | ||
|
||
NriStruct(MemoryMTLDesc) | ||
{ | ||
uint64_t size; | ||
// MTLStorageMode storage; | ||
|
||
//MTLResourceOptions options; | ||
}; | ||
|
||
NRI_API Nri(Result) NRI_CALL nriCreateDeviceFromMtlDevice(const NriRef(DeviceCreationMTLDesc) deviceDesc, NriRef(Device*) device); | ||
|
||
NriNamespaceEnd | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#import <MetalKit/MetalKit.h> | ||
|
||
#include "SharedExternal.h" | ||
|
||
using namespace nri; | ||
|
||
// referenced from Molten VK | ||
static uint32_t GetEntryProperty(io_registry_entry_t entry, CFStringRef propertyName) { | ||
|
||
uint32_t value = 0; | ||
|
||
CFTypeRef cfProp = IORegistryEntrySearchCFProperty(entry, | ||
kIOServicePlane, | ||
propertyName, | ||
kCFAllocatorDefault, | ||
kIORegistryIterateRecursively | | ||
kIORegistryIterateParents); | ||
if (cfProp) { | ||
const uint32_t* pValue = reinterpret_cast<const uint32_t*>(CFDataGetBytePtr((CFDataRef)cfProp)); | ||
if (pValue) { value = *pValue; } | ||
CFRelease(cfProp); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
|
||
static int SortAdaptersByDedicatedVideoMemorySize(const void* pa, const void* pb) { | ||
AdapterDesc* a = (AdapterDesc*)pa; | ||
AdapterDesc* b = (AdapterDesc*)pb; | ||
|
||
if (a->videoMemorySize > b->videoMemorySize) | ||
return -1; | ||
|
||
if (a->videoMemorySize < b->videoMemorySize) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|
||
NRI_API Result NRI_CALL nriEnumerateAdapters(AdapterDesc* adapterDescs, uint32_t& adapterDescNum) { | ||
|
||
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices(); | ||
if(!adapterDescs) { | ||
adapterDescNum = (uint32_t)devices.count; | ||
return Result::SUCCESS; | ||
} | ||
|
||
AdapterDesc* adapterDescsSorted = (AdapterDesc*)alloca(sizeof(AdapterDesc) * devices.count); | ||
for(size_t i = 0; i < devices.count; i++) { | ||
NSString* name = [devices[i] name]; | ||
[name getCString:adapterDescsSorted[i].name maxLength: sizeof(adapterDescs[i].name) - 1 encoding: NSASCIIStringEncoding]; | ||
const uint64_t regID = [devices[i] registryID]; | ||
adapterDescsSorted[i].luid = regID; | ||
if (regID) | ||
{ | ||
io_registry_entry_t entry = IOServiceGetMatchingService(MACH_PORT_NULL, IORegistryEntryIDMatching(regID)); | ||
if (entry) | ||
{ | ||
// That returned the IOGraphicsAccelerator nub. Its parent, then, is the actual PCI device. | ||
io_registry_entry_t deviceEntry; | ||
if (IORegistryEntryGetParentEntry(entry, kIOServicePlane, &deviceEntry) == kIOReturnSuccess) | ||
{ | ||
adapterDescsSorted[i].vendor = GetVendorFromID(GetEntryProperty(deviceEntry, CFSTR("vendor-id"))) ; | ||
adapterDescsSorted[i].deviceId = GetEntryProperty(deviceEntry, CFSTR("device-id")); | ||
} | ||
} | ||
} else { | ||
adapterDescsSorted[i].vendor = nri::Vendor::APPLE; | ||
} | ||
adapterDescsSorted[i].videoMemorySize = [devices[i] recommendedMaxWorkingSetSize]; | ||
NSProcessInfo *pinfo = [NSProcessInfo processInfo]; | ||
adapterDescsSorted[i].systemMemorySize = [pinfo physicalMemory]; | ||
} | ||
|
||
// Sort by video memory size | ||
qsort(adapterDescsSorted, devices.count, sizeof(adapterDescsSorted[0]), SortAdaptersByDedicatedVideoMemorySize); | ||
for(size_t i = 0; i < MIN(devices.count, adapterDescNum); i++) { | ||
adapterDescs[i] = adapterDescsSorted[i]; | ||
} | ||
adapterDescNum = (uint32_t)MIN(devices.count, adapterDescNum); | ||
return Result::SUCCESS; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like these are #defined in apple framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind to add these undefs to the interface.